/**
 * 获取本周、本季度、本月、上月的开始日期、结束日期
 */
define(function(require, exports, module) {

	var now = new Date(); //当前日期
	var nowDayOfWeek = now.getDay(); //今天本周的第几天
	var nowDay = now.getDate(); //当前日
	var nowMonth = now.getMonth(); //当前月
	var nowYear = now.getFullYear(); //当前年 
	var nowHour = now.getHours();
	var nowMinute = now.getMinutes();
	var nowSecond = now.getSeconds();

	var lastMonthDate = new Date(); //上月日期
	lastMonthDate.setDate(1);
	lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
	var lastYear = lastMonthDate.getYear();
	var lastMonth = lastMonthDate.getMonth();

	Date.prototype.Format = function(fmt) { //author: meizz 
		try {

			if(this.getTime() == 62135596800000 || this.getTime() == -62135596800000) {
				return "";
			}
			var o = {
				"M+": this.getMonth() + 1, //月份 
				"d+": this.getDate(), //日 
				"H+": this.getHours(), //小时 
				"m+": this.getMinutes(), //分 
				"s+": this.getSeconds(), //秒 
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
				"S": this.getMilliseconds() //毫秒 
			};
			if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
			for(var k in o)
				if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			return fmt;
		} catch(e) {
			console.log(e);
		}
		return "";
	};

	//获得某月的天数
	function getMonthDays(myMonth) {
		var monthStartDate = new Date(nowYear, myMonth, 1);
		var monthEndDate = new Date(nowYear, myMonth + 1, 1);
		var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
		return days;
	}
	//获得本季度的开端月份
	function getQuarterStartMonthOut() {
		var quarterStartMonth = 0;
		if(nowMonth < 3) {
			quarterStartMonth = 0;
		}
		if(2 < nowMonth && nowMonth < 6) {
			quarterStartMonth = 3;
		}
		if(5 < nowMonth && nowMonth < 9) {
			quarterStartMonth = 6;
		}
		if(nowMonth > 8) {
			quarterStartMonth = 9;
		}
		return quarterStartMonth;
	}
	var getScreenDataList = {
		//获得本季度的开端月份 
		getQuarterStartMonth: function() {
			var quarterStartMonth = 0;
			if(nowMonth < 3) {
				quarterStartMonth = 0;
			}
			if(2 < nowMonth && nowMonth < 6) {
				quarterStartMonth = 3;
			}
			if(5 < nowMonth && nowMonth < 9) {
				quarterStartMonth = 6;
			}
			if(nowMonth > 8) {
				quarterStartMonth = 9;
			}
			return quarterStartMonth;
		},
		//获得本周的开端日期
		getWeekStartDate: function() {
			if(nowDayOfWeek === 0) {
				var weekStartDate = new Date(nowYear, nowMonth, nowDay - 6);
			} else {
				var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1);
			}

			return weekStartDate;
		},
		//获得本周的停止日期
		getWeekEndDate: function() {
			if(nowDayOfWeek === 0) {
				var weekEndDate = new Date(nowYear, nowMonth, nowDay);
			} else {
				var weekEndDate = new Date(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek));
			}

			return weekEndDate;
		},
		//获得上周的开端日期
		getLastWeekStartDate: function() {
			if(nowDayOfWeek === 0) {
				var weekStartDate = new Date(nowYear, nowMonth, nowDay - 13);
			} else {
				var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 6);
			}

			return weekStartDate;
		},
		//获得上周的停止日期
		getLastWeekEndDate: function() {
			if(nowDayOfWeek === 0) {
				var weekEndDate = new Date(nowYear, nowMonth, nowDay - 7);
			} else {
				var weekEndDate = new Date(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek - 7));
			}

			return weekEndDate;
		},
		//获得本月的开端日期
		getMonthStartDate: function() {
			var monthStartDate = new Date(nowYear, nowMonth, 1);
			return monthStartDate;
		},
		//获得本月的停止日期
		getMonthEndDate: function() {
			var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
			return monthEndDate;
		},
		//获得上月开端时候
		getLastMonthStartDate: function() {
			var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
			return lastMonthStartDate;
		},
		//获得上月停止时候
		getLastMonthEndDate: function() {
			var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
			return lastMonthEndDate;
		},
		//获得本季度的开端日期
		getQuarterStartDate: function() {
			var quarterStartDate = new Date(nowYear, getQuarterStartMonthOut(), 1);
			return quarterStartDate;
		},
		//或的本季度的停止日期
		getQuarterEndDate: function() {
			var quarterEndMonth = getQuarterStartMonthOut() + 2;
			var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
			return quarterStartDate;
		},
		getYearStartDate: function() {
			var YearStartDate = new Date(nowYear, 0, 1);
			return YearStartDate;
		},
		getYearEndDate: function() {
			var YearEndDate = new Date(nowYear, 11, 31);
			return YearEndDate;
		}
	};

	module.exports = getScreenDataList;

	//	子页面调用方法
	//	var getScreenDataList=require("getScreenData");
	//	console.log(getScreenDataList.getQuarterEndDate());
});